package com.kathir.database.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class main {

	public static void main(String[] args) throws IOException {
		while(true)
			{
			System.out.println("Enter the Option");
			System.out.println("1.Bc_Master");
			System.out.println("2.Branch_Master");
			System.out.println("3.Device_Master");
			System.out.println("4.Village_Master");
			System.out.println("5.History");
			BufferedReader brObj= new BufferedReader(new InputStreamReader(System.in));
			String value = brObj.readLine();			
			if (value.equals("1")) {
				System.out.println("1.Enter the Agent ID");
				BufferedReader brObj1= new BufferedReader(new InputStreamReader(System.in));
				String value1 = brObj1.readLine();	
				int id= Integer.parseInt(value1);
				System.out.println("1.Enter the BC Name");
				BufferedReader brObj2= new BufferedReader(new InputStreamReader(System.in));
				String value2 = brObj2.readLine();	
				//int Name= Integer.parseInt(value2);
				try {
					Class.forName("com.mysql.jdbc.Driver");
					Connection connect = DriverManager.getConnection("jdbc:mysql://localhost/kathir?user=root&password=gowtham");
					Statement statement = connect.createStatement();
					statement.execute("INSERT INTO BC_MASTER (AGENT_ID,BC_NAME) VALUES ("+id+",'"+value2+"')");
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

				
			}
			if (value.equals("2"))
			{
				System.out.println("1.Enter the Branch Code");
				BufferedReader brObj1= new BufferedReader(new InputStreamReader(System.in));
				String value1 = brObj1.readLine();	
				int id= Integer.parseInt(value1);
				System.out.println("1.Enter the Branch Name");
				BufferedReader brObj2= new BufferedReader(new InputStreamReader(System.in));
				String value2 = brObj2.readLine();
				System.out.println("1.Enter the Region Name");
				BufferedReader brObj3= new BufferedReader(new InputStreamReader(System.in));
				String value3 = brObj3.readLine();
				try {
					Class.forName("com.mysql.jdbc.Driver");
					Connection connect = DriverManager.getConnection("jdbc:mysql://localhost/kathir?user=root&password=gowtham");
					Statement statement = connect.createStatement();
					statement.execute("INSERT INTO BRANCH_MASTER (BRANCH_CODE,BRANCH_NAME,REGION_NAME) VALUES ("+id+",'"+value2+"','"+value3+"')");
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if (value.equals("3"))
			{
				System.out.println("1.Enter the Device No");
				BufferedReader brObj1= new BufferedReader(new InputStreamReader(System.in));
				String value1 = brObj1.readLine();	
				int id= Integer.parseInt(value1);
				System.out.println("1.Enter the Device Name");
				BufferedReader brObj2= new BufferedReader(new InputStreamReader(System.in));
				String value2 = brObj2.readLine();
				try {
					Class.forName("com.mysql.jdbc.Driver");
					Connection connect = DriverManager.getConnection("jdbc:mysql://localhost/kathir?user=root&password=gowtham");
					Statement statement = connect.createStatement();
					statement.execute("INSERT INTO DEVICE_MASTER (DEVICE_NO,DEVICE_NAME) VALUES ("+id+",'"+value2+"')");
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if (value.equals("4"))
			{
				System.out.println("1.Enter the Village Code");
				BufferedReader brObj1= new BufferedReader(new InputStreamReader(System.in));
				String value1 = brObj1.readLine();	
				int id= Integer.parseInt(value1);
				System.out.println("1.Enter the Village Name");
				BufferedReader brObj2= new BufferedReader(new InputStreamReader(System.in));
				String value2 = brObj2.readLine();
				try {
					Class.forName("com.mysql.jdbc.Driver");
					Connection connect = DriverManager.getConnection("jdbc:mysql://localhost/kathir?user=root&password=gowtham");
					Statement statement = connect.createStatement();
					statement.execute("INSERT INTO VIllAGE_MASTER (VILLAGE_CODE,VILLAGE_NAME) VALUES ("+id+",'"+value2+"')");
				} catch (ClassNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}


			}

	}

}
